package com.cloudstreamservice8001.controller;

import com.cloudstreamservice8001.common.Result;
import com.cloudstreamservice8001.entity.DeliveryProcess;
import com.cloudstreamservice8001.param.DeliverInfoCreatOrUpdateParam;
import com.cloudstreamservice8001.param.DeliverInfoDeleteParam;
import com.cloudstreamservice8001.service.DeliveryProcessService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/deliveryProcess")
public class DeliveryProcessController {
    @Resource
    private DeliveryProcessService deliveryProcessService;

    /**
     * 获取配送过程列表
     * 分页查询
     *
     * @return
     */
    @GetMapping("/list")
    public Result list(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,@RequestParam(value = "deliveryId",  required = false) Long deliveryId) {
        return Result.success(deliveryProcessService.getDeliveryProcessList(pageNum, pageSize, deliveryId));
    }

    /**
     * 创建/更新配送过程信息
     * @param
     * @return
     */
    @PostMapping(value = {"/create", "/update"})
    public Result createOrUpdate(@RequestBody DeliveryProcess deliveryProcess) {
        if (deliveryProcess.getId() == null) {
            deliveryProcessService.create(deliveryProcess);
            return Result.success("创建成功");
        }
        deliveryProcessService.updates(deliveryProcess);
        return Result.success("更新成功");
    }

    /**
     * 删除配送信息
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody DeliveryProcess deliveryProcess) {
        if(deliveryProcess.getId() != null){
            boolean delete = deliveryProcessService.removeById(deliveryProcess.getId());
            return delete ? Result.success("删除成功") : Result.error("删除失败");
        }
        if(deliveryProcess.getDeliveryId() != null){
            boolean delete = deliveryProcessService.removeDeliveryId(deliveryProcess.getDeliveryId());
            return delete ? Result.success("删除成功") : Result.error("删除失败");
        }
        return Result.error("参数错误");
    }





}
